Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handleResponse hook for logging/monitoring which route was matched #3907

Closed

Conversation

georgecrawford
Copy link
Contributor

This is a very speculative PR, with no tests or types yet. I'm interested what the view is from the maintainers about the use-case and the approach.

Fixes #3840

From that issue:

I'm keen to implement good logging and monitoring for my SvelteKit app. For monitoring, in particular, it's extremely useful to know which route, and which params, produced the final response. I use Prometheus, and with my old Express.js app I'd typically label each finished request/response with details like {method: 'GET', route: '/users/[id]/details', status: 200}. This generic route parameter means that I can aggregate all similar requests to the same route and understand how long the responses took to generate on average (or stddev, etc). At present, since I don't know which route rendered the response in handle(), the best I can do is to use url.pathname, which means I can't aggregate across similar request to the same route.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Feb 14, 2022

⚠️ No Changeset found

Latest commit: 61c2d96

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Feb 14, 2022

✔️ Deploy Preview for kit-demo canceled.

🔨 Explore the source changes: 61c2d96

🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/620acde104cb8600087576a1

@Rich-Harris
Copy link
Member

It took a while, but we're finally in a position to address this issue. A new hook isn't ideal, and nor is exposing the internal route object, but by getting rid of fallthrough routes (#4330) we can determine the route before we even call handle, which means we can expose the internal route.key property on the event, which means you can do the logging inside handle.

Closing in favour of #4345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement post-response hook for logging and monitoring, including matched route and params
2 participants